package info.javafans.cdn.database;


import java.beans.PropertyVetoException;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.Properties;

import com.mchange.v2.c3p0.ComboPooledDataSource;

public class C3p0Conn implements DbConn {
	@Override
	public Connection getConnection(Properties prop) {
		Connection conn = null;
		ComboPooledDataSource cpds = new ComboPooledDataSource();
		try {
			cpds.setDriverClass(prop.getProperty("drivername"));
		} catch (PropertyVetoException e) {
			e.printStackTrace();
		}
		cpds.setJdbcUrl(prop.getProperty("url"));
		cpds.setUser(prop.getProperty("username"));
		cpds.setPassword(prop.getProperty("password"));
		cpds.setMaxPoolSize(200);
		try {
			conn = cpds.getConnection();
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return conn;
	}
}